package basic.study.leetcode;

/**
 * @ClassName Problem11
 * @Description 盛水最多的容器
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/17 8:57
 * @Version 1.0
 */
public class Mid11 {
    /**
     * 双指针法
     */
    class Solution {
        public int maxArea(int[] hight) {
            int left = 0;
            int right = hight.length -1;
            int max = 0;

            while (left < right) {
                int diff = right - left;
                int area = diff * Math.min(hight[left], hight[right]);
                max = Math.max(max, area);

                if (hight[left] < hight[right]) {
                    left++;
                } else {
                    right--;
                }
            }
            return max;
        }
    }
}
